﻿using System;

namespace FStore.Formats
{
    /// <summary>
    /// Interface for allowing objects to be stored in a certain format
    /// </summary>
    public interface IFlatFormat
    {
        /// <summary>
        /// Decomposes an instance of type <typeparamref name="T"/> into a string of the format
        /// utilised by the implementation of this interface
        /// </summary>
        /// <typeparam name="T">The type of the instance to be decomposed</typeparam>
        /// <param name="obj">The instance to decompose</param>
        /// <returns>The string in the format utilised by the implementation of this interface</returns>
        string Decompose<T>(T obj);

        /// <summary>
        /// Decomposes an instance of a given type into a string of the format
        /// utilised by the implementation of this interface
        /// </summary>
        /// <param name="type">The type of the instance to be decomposed</param>
        /// <param name="obj">The instance to decompose</param>
        /// <returns>The string in the format utilised by the implementation of this interface</returns>
        string Decompose(Type type, Object obj);

        /// <summary>
        /// Composes an instance of type <typeparamref name="T"/> from a string in the format
        /// utilised by the implementation of this interface
        /// </summary>
        /// <typeparam name="T">The type of the instance to be composed</typeparam>
        /// <param name="str">The string in the format utilised by the implementation of this interface</param>
        /// <returns>The composed instance of <typeparamref name="T"/></returns>
        T Compose<T>(string str);

        /// <summary>
        /// Composes an instance of a given type from a string in the format
        /// utilised by the implementation of this interface
        /// </summary>
        /// <param name="type">The type of the instance to be composed</param>
        /// <param name="str">The string in the format utilised by the implementation of this interface</param>
        /// <returns>The composed instance</returns>
        Object Compose(Type type, string str);
    }
}
